﻿using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web.UI;
using System.Reflection;

using Developmentalmadness.Web.UI.AjaxAbstractions;

namespace Developmentalmadness.Web.UI.ExtJsControlLibrary
{
    public class ExtJsColorPalette : ExtJsComponent
    {
        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.ColorPalette";

            String[] properties = new String[]{
                "allowReselect", "itemCls", "tpl", "value", "colors"
            };

            Type component = typeof(ExtJsDatePicker);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'Ext.ColorPalette.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                    continue;

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            return list;
        }


        #region Public Properties

        public Boolean? allowReselect { get; set; }

        public String itemCls { get; set; }

        public String tpl { get; set; }

        public String value { get; set; }

        public String colors { get; set; }

        #endregion

    }
}
